<?php
	/* Configure Validation Map*/
	echo App::Load("Helper/Javascript")->validation_map(
														Array(
																'_errBg'=>ERROR_BACKGROUND,
																'_dflBg'=>'#CFCFCF',
																'_autoSubmit'=>'false',
																'_errToolTips'=>'false',
																'_errorMark' => 'inline'
															)
													);
	/* Configure the ajax submit form */
	echo App::Load("Helper/Javascript")->ajax_submit(array("form_name"=>".app_validation","debug"=>"true","auto_hide"=>"true","message_element"=>".message"));
	?>
	<p><span class="message">&nbsp;</span></p>
<form action="<?php echo $this->baseurl("/pcjobs/create/{$srcType}") ?>" class="app_validation" method="post">
<?php
	$userSession =  App::Module("Session")->read('User');
	App::Module('DataGrid') ->setDisplay('FormListing')
							->addRow('Title *',App::load("Helper/Html")->inputTag("data[Job][title]",(isset($SelectJob['title'])?$SelectJob['title']:""),array("id"=>"title","class"=>"app_input check_notempty")) )
							->addRow('Description',App::load("Helper/Html")->textareaTag("data[Job][description]",(isset($SelectJob['description'])?$SelectJob['description']:""),array("id"=>"description","rows"=>"7","class"=>"app_input")) )
							->addRow('Service',App::CategorySet("services")->Tag("data[Job][service_id]",(isset($SelectJob['service_id'])?$SelectJob['service_id']:""),array("fetch"=>"all"),array("id"=>"services")))
							->addRow('Delivery Time',App::CategorySet("delivery-time")->Tag("data[Job][delivery_time]",(isset($SelectJob['delivery_time'])?$SelectJob['delivery_time']:""),array("fetch"=>"all"),array("id"=>"deliverytime")))
							->addRow('Delivery Type',App::CategorySet("delivery-type")->Tag("data[Job][delivery_type]",(isset($SelectJob['delivery_type'])?$SelectJob['delivery_type']:""),array("fetch"=>"all"),array("id"=>"deliverytype")));

		App::Module('DataGrid') ->addRow('Upload Image',App::load("Helper/Html")->inputTag("file_upload","",array("id"=>"file_upload")) );
		App::Module('DataGrid') ->Render();

?>
</form>
<script type="text/javascript">
	jQuery(document).ready(function() {
		var TOKEN = '<?php echo time() ?>';
		jQuery('#file_upload').uploadify({
		  'uploader'  : siteInfo.baseUrl + '/addons/uploadify/uploadify.swf',
		  'script'    : siteInfo.baseUrl + '/pcjobs/uploadfiles',
		  'cancelImg' : siteInfo.baseUrl + '/addons/uploadify/cancel.png',
		  'multi'     : true,
		  'auto'      : false,
		  'onAllComplete' 	: function(event,data)
							  {
								alert(data.filesUploaded + ' files uploaded successfully!');
								window.location = siteInfo.baseUrl + '/pcjobs/uploadfiles/' + TOKEN;
							  },

			'onSelectOnce'  : function(event,ID,fileObj)
							  {
									if(jQuery('#title').val() == "")
									{
										jQuery('#title').addClass('error');
										alert('Please enter Job Title');
										jQuery('#file_upload').uploadifyClearQueue();
									}
									else
									{
										if(confirm("Press\n'OK' to Submit Order \n'Cancel' to Add more file"))
										{
											jQuery('#file_upload').uploadifySettings("scriptData",{
											"clientid" : <?php echo $userSession['id']; ?>,
											'title':jQuery('#title').val(),
											'description':jQuery('#description').val(),
											'token':TOKEN,
											'services':jQuery('#services').val(),
											'deliverytime':jQuery('#deliverytime').val(),
											'deliverytype':jQuery('#deliverytype').val()
											});

											jQuery('#title').removeClass('error');
											jQuery('#file_upload').uploadifyUpload();
										}
									}
							  }
		  });
	});
</script>